const wcs = require('../utils/wcs/index')
const config = require('../config')
const logger = require('../logger')

// 取货中-taking
// 申请取货-applyTake
// 取货完成-takeFinish
// 放货中-puting
// 申请放货-applyPut
// 放货完成-putFinish
// 非终点位放货完成-NoTargetPutFinish
// 任务异常完成-errorFinish
// 异常-exception
// 作废-deprecate

class AgvCallback {
	constructor() {
	
	}

	async callback(ctx) {

		const body = ctx.request.body

		console.log(body)

		ctx.body = {
			code    : 0,
			message : '成功',
			reqCode : body.reqCode || ''
		}

		const {
			taskCode,
			currentPositionCode,
			taskTyp,
			robotCode,
			method
		} = body

		if (config.taskFeed.includes(method)) {
			logger.debug('反馈指定动作')
			const payload = {
				taskCode       : taskCode,
				carId          : robotCode,
				taskType       : taskTyp || '',
				feedbackStatus : method
			}
	
			const response = await wcs.notice(payload)
	
			console.log(response)
		}
		else {
			logger.debug('非指定动作')
		}
	}
}

module.exports = new AgvCallback()
